package com.brillilab.service.module.message.template.impl.instrument;

import com.brillilab.domain.enums.instrument.CancelTypeEnum;
import com.brillilab.domain.po.instrument.Instrument;
import com.brillilab.domain.po.instrument.InstrumentAppointment;
import com.brillilab.domain.vo.instrument.AppointmentVo;
import com.brillilab.domain.vo.user.UserInfoVo;
import com.brillilab.service.logic.instrument.converter.AppointmentConverter;
import com.brillilab.service.module.message.template.AbstractMessageTemplate;
import com.brillilab.service.module.message.template.enums.MessageTypeEnum;
import lombok.Data;

@Data
public class AppointmentCancelTemplate extends AbstractMessageTemplate {

    private Integer cancelType;
    private String labName;
    private Integer instrumentNo;
    private String instrumentName;
    private String startTime;
    private String endTime;

    public AppointmentCancelTemplate(Integer cancelType,Instrument instrument,InstrumentAppointment appointment,UserInfoVo userInfo) {
        super(userInfo.getLabId(),userInfo.getId());
        AppointmentVo appointmentVo=AppointmentConverter.appointmentToAppointmentVo(appointment);
        this.cancelType=cancelType;
        this.labName=userInfo.getLabName();
        this.labMemberId = userInfo.getLabMemberId();
        this.instrumentNo=instrument.getNo();
        this.instrumentName=instrument.getName();
        this.startTime=appointmentVo.getStartDate();
        this.endTime=appointmentVo.getEndDate();
        this.referId = appointmentVo.getId();
        super.setType(MessageTypeEnum.InstrumentAppointmentCancel.getValue());
        super.setTitle("仪器预约取消");

        StringBuilder context=new StringBuilder();
        if(cancelType.equals(CancelTypeEnum.ADMIN_CANCEL.getValue())){
            context.append("<span>管理员已取消您预约好的").append(this.labName)
                    .append("，编号为").append(this.instrumentNo)
                    .append("的仪器：").append(this.instrumentName)
                    .append("，预约时间为：").append(this.startTime)
                    .append(" 到 ").append(this.endTime).append("</span>");
        }
        if(cancelType.equals(CancelTypeEnum.OFF_SERVICE_CANCEL.getValue())){
            context.append("<span>由于仪器被停用，您的预约已被取消：").append(this.labName)
                    .append("，编号为").append(this.instrumentNo)
                    .append("的仪器：").append(this.instrumentName)
                    .append("，预约时间为：").append(this.startTime)
                    .append(" 到 ").append(this.endTime).append("</span>");
        }
        if(cancelType.equals(CancelTypeEnum.USER_CANCEL.getValue())){
            context.append("<span>您已成功取消您的预约：").append(this.labName)
                    .append("，编号为").append(this.instrumentNo)
                    .append("的仪器：").append(this.instrumentName)
                    .append("，预约时间为：").append(this.startTime)
                    .append(" 到 ").append(this.endTime).append("</span>");
        }

        super.setContent(context.toString());
        super.setAppContent(context.toString());
    }

}
